﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=1501",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$1501");
                    tabs.removeTab(tab);
                }
            }
        });
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom:0;">
        <table>
            <tr>
                <td>
                    名称：
                    <input class="mini-textbox" id="key" emptytext="关键字" />
                    状态：
                    <input id="state" class="mini-combobox" style="width: 60px;" data="StateAll" value="1" required="true" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow();">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                </td>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetActorList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer">操作</div>
                <div field="ac_name" headeralign="center" align="center" allowsort="true">
                    名称</div>
                <div field="ac_state" width="50px" headeralign="center" align="center" allowsort="true" renderer="onStateRenderer">
                    状态</div>
                <div field="ac_inserttime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    添加时间</div>
                <div field="ac_insertuser" width="50px" headeralign="center" align="center" allowsort="true">
                    添加人</div>
                <div field="ac_insertip" width="70px" headeralign="center" align="center" allowsort="true">
                    添加IP</div>
                <div field="ac_modifytime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    修改时间</div>
                <div field="ac_modifyuser" width="50px" headeralign="center" align="center" allowsort="true">
                    修改人</div>
                <div field="ac_modifyip" width="70px" headeralign="center" align="center" allowsort="true">
                    修改IP</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="角色信息" style="width: 360px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="ac_no" id="ac_no" />
            <input class="mini-hidden" name="ac_mlno" id="ac_mlno"/>
            <table style="width: 98%; height: 100%;">
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 20%;">
                        <span class="red">*</span>名称：
                    </td>
                    <td class="tdtext">
                        <input name="ac_name" class="mini-textbox" required="true" style="width:120px;"/>
                    </td>
                </tr>
                <tr>
                    <td class="tdtitle">
                        <span class="red">*</span>权限：
                    </td>
                    <td class="tdtree">
                        <div class="divtree">
                            <ul id="tree1" class="mini-tree" style="width:100%;height:180px;"
                                showTreeIcon="true" textField="ml_name" idField="ml_no" parentField="ml_pid" resultAsTree="false"  
                                showCheckBox="true" checkRecursive="true" expandOnLoad="false" allowSelect="false" enableHotTrack="false">
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>状态：
                    </td>
                    <td class="tdtext">
                        <input name="ac_state" class="mini-radiobuttonlist" data="State" value="1" required="true" />
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                // 通过XMLHttpRequest取得响应头，sessionstatus
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function addRow() {
            var form = new mini.Form("#editform");
            form.reset();
            form.loading();
            form.unmask();
            var tree = mini.get("tree1");
            tree.load("../data/system.aspx?method=GetMenuTree");
            var win = mini.get("editWindow");
            win.setTitle("新增角色<span class='red'>( 带 * 号的必须填写)");
            if (!win.visible)
                win.show();
        }

        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var win = mini.get("editWindow");
                var form = new mini.Form("#editform");
                form.clear();
                form.loading();
                var tree = mini.get("tree1");
                tree.load("../data/logincheck.aspx?method=GetMenuTree&id=" + row.ac_no);
                $.ajax({
                    url: "../data/system.aspx?method=GetActor&id=" + row.ac_no,
                    success: function (text) {
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        form.unmask();
                        var o = mini.decode(text);
                        form.setData(o);
                        win.setTitle("编辑角色<span class='red'>( 带 * 号的必须填写)");
                        win.show();
                    },
                    error: function () {
                        ShowMessage("系统提示", "表单加载错误！", 3);
                        form.unmask();
                    }
                });
            }
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此角色？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            var messageid = mini.loading("删除中，请稍后......", "系统提示");
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteActor",
                                type: "post",
                                data: { id: row.ac_no },
                                success: function (ret) {
                                    mini.hideMessageBox(messageid);
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "角色删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "角色删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.hideMessageBox(messageid);
                                    ShowMessage("系统提示", "角色删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function updateRow() {
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false) return;
            var nodes = mini.get("tree1").getCheckedNodes();
            if (nodes.length == 0) {
                ShowMessage("系统提示", "请选择权限！", 2);
                return;
            }
            var ids = [];
            for (var i = 0; i < nodes.length; i++) {
                var node = nodes[i];
                if (node.ml_pid > 0)
                    ids.push(node.ml_no);
            }
            mini.get("ac_mlno").setValue(ids.join(","));
            var o = form.getData();

            var messageid = mini.loading("保存中，请稍后......", "系统提示");
            var json = mini.encode(o);

            $.ajax({
                url: "../data/system.aspx?method=SaveActor",
                data: { data: json },
                success: function (ret) {
                    mini.hideMessageBox(messageid);
                    var editWindow = mini.get("editWindow");
                    if (ret > 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "角色保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该角色已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else
                        ShowMessage("系统提示", "角色保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.hideMessageBox(messageid);
                    ShowMessage("系统提示", "角色保存失败！", 3);
                }
            });
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选角色？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            var messageid = mini.loading("删除中，请稍后......", "系统提示");
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].ac_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteActor",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.hideMessageBox(messageid);
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "角色删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "角色删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.hideMessageBox(messageid);
                                    ShowMessage("系统提示", "角色删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要删除的角色！", 2);
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }

        function search() {
            var state = mini.get("state").getValue();
            var key = mini.get("key").getValue();
            grid.load({ state: state, key: key });
            grid.sortBy("ac_no", "asc");
        }
    </script>
</body>
</html>
